package com.yixun.qfbao.hander;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.apidto.GetPremisesCMListReqDto;
import com.yixun.qfbao.apidto.GetPremisesCMListResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.GetPremisesCMListReqVo;
import com.yixun.qfbao.xf.model.Premises;
import com.yixun.qfbao.xf.model.dto.CaseMemberDto;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import com.yixun.qfbao.xf.service.CaseMemberService;
import com.yixun.qfbao.xf.service.PremisesService;

/**
 * 楼盘驻守人员及人员驻守的其他楼盘
 * 
 * @author JHSong
 *		
 */
@Service("getPremisesCMListHander")
public class GetPremisesCMListHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(GetPremisesCMListHander.class);
	
	
	@Autowired
	private CaseMemberService caseMemberService;
	@Autowired
	private PremisesService premisesService;
	
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		GetPremisesCMListReqVo req = (GetPremisesCMListReqVo)reqDto;
		GetPremisesCMListReqDto reqDto1 = req.getParams();
		BaseResponseDTO<GetPremisesCMListResDto> res = new BaseResponseDTO<GetPremisesCMListResDto>();
		GetPremisesCMListResDto resDto = new GetPremisesCMListResDto();
		try {
			List<CaseMemberDto> cmDtoList = new ArrayList<CaseMemberDto>();
			if(!StringUtils.isBlank(reqDto1.getPremisesId())) {
				Premises premises = premisesService.selectSimpleById(Long.valueOf(reqDto1.getPremisesId()));
				CaseMemberDto cmDto = new CaseMemberDto();
				cmDto.setPremisesId(Long.valueOf(reqDto1.getPremisesId()));
				cmDto.setCompanyId(premises.getCompanyId());
				cmDtoList = caseMemberService.getPremisesCMList(cmDto);
				resDto.setCmDtoList(cmDtoList);
			}
		} catch (Exception e) {
			logger.error("GetPremisesCMListHander error: {}", e);
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg("驻守楼盘列表获取失败!");
		}
		res.setResData(resDto);
		res.setResult(resDto.getResult());
		return res;
	}
	
}
